// pages/borrowapply_public/borrowapply_public.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    startdate: '2020-1-1',
    enddate: '2030-1-1'
  },
  // 开始时间选择事件
  startbindDateChange: function (e) {
    this.setData({
      startdate: e.detail.value
    })
    var start = (new Date((this.data.startdate.replace(/-/g, "/"))));
    var end = (new Date((this.data.enddate.replace(/-/g, "/"))));
    var days = parseInt((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
    if (days < 0) {
      wx.showToast({
        title: '请选择正确的时间',
      })
      this.setData({
        startdate: '',
        enddate: ''
      })
      this.totaldays();
    }
    this.totaldays();
  },
  // 结束时间选择事件
  endbindDateChange: function (e) {
    this.setData({
      enddate: e.detail.value
    })
    var start = (new Date((this.data.startdate.replace(/-/g, "/"))));
    var end = (new Date((this.data.enddate.replace(/-/g, "/"))));
    var days = parseInt((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));

    if (days < 0) {
      wx.showToast({
        title: '请选择正确的时间',
      })
      this.setData({
        startdate: '',
        enddate: ''
      })
      this.totaldays();
    }
    this.totaldays();
  },
  // 差值天数事件
  totaldays() {
    var start = (new Date((this.data.startdate.replace(/-/g, "/"))));
    var end = (new Date((this.data.enddate.replace(/-/g, "/"))));
    var days = parseInt((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
    this.setData({
      totaldays: days
    })
  },
  // 页面加载事件
  onLoad: function (options) {
    this.totaldays();
  },

})